﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BFlatCompile.Nodes
{
	public class SwitchCase : ICodeContainer
	{
		public bool IsDefault { get; private set; }
		public Expression Expression { get; private set; }
		public Executable[] Code { get; private set; }

		public SwitchCase(Expression expression, Executable[] code)
		{
			this.IsDefault = expression == null;
			this.Expression = expression;
			this.Code = code;
		}

		public void ResolveCode(Class c, Dictionary<object, object> parents)
		{
			this.Expression.ResolveCode(c, parents); // should be unnecessary
			foreach (Executable line in this.Code)
			{
				line.ResolveCode(c, parents);
			}
		}

		public void ResolveClassToThis(Class c)
		{
			foreach (ICodeContainer code in new Consolidator().Add(this.Expression).Add(this.Code).List())
			{
				code.ResolveClassToThis(c);
			}
		}
	}
}
